import os, cv2, json, math, statistics
from glob import glob

img_dir_path = "/home/smartgis/workspace/data/风电/预巡/label"
json_path_list = glob(img_dir_path+"/*.json")


def get_len(point1,point2):
    len_size = math.sqrt((point1[0]-point2[0])**2+((point1[1]-point2[1])**2))
    return len_size


for json_path in json_path_list:
    head = []
    apexs = []
    with open(json_path,"r") as f:
        label_json = json.load(f)
    img_path = img_dir_path+"/"+label_json["imagePath"].replace("\\","/")
    img_data = cv2.imread(img_path)
    cv2.imwrite("temp.jpg",cv2.resize(img_data,[800,600]))
    for shape in label_json["shapes"]:
        if shape["label"] == "风帽" :
            head = shape["points"][0]
        elif "叶尖" in shape["label"]:
            apexs.append(shape["points"][0])

    len_1 = get_len(apexs[0],apexs[1])
    len_2 = get_len(apexs[1],apexs[2])
    len_3 = get_len(apexs[2],apexs[0])
    mean_value = max([len_1,len_2,len_3])/10
    variance = statistics.stdev([len_1,len_2,len_3])
    if len(head)>0:
        have_head = True
    else:
        have_head = False
    print("{:.2f}, {:.2f}, {:.2f}, {:.2f} | {}".format(variance/mean_value, len_1,len_2,len_3, have_head))
    if variance/mean_value <=0.25:
        print("")

